<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;
class Me extends Base
{
     //个人中心页
     public function index()
     {
        return $this->fetch();
     }
     //修改手机号页
     public function updatephone()
     {
        return $this->fetch();
     }
      //处理修改手机号
      public function updatephone1()
      {
        $user_id = \think\Session::get('user_id');
        $date = [
            'user_phone' =>input('user_phone'),
         ];
        //  dump($date);
        //  exit;
         $res = Db::name('user')->where('user_id',$user_id)->update($date);
         if($res)
        {
            return $this->success('修改成功','me/index');
        }
        else{
            return  $this->error('失败，请重新操作');
        }
      }
     //修改密码页
     public function updatepw()
     {
        return $this->fetch();
     }
     //处理修改密码
     public function updatepw1()
     {
        $user_id = \think\Session::get('user_id');
        $user_pw = md5(input('pw'));
        $res = Db::name('user')->where('user_id',$user_id)->where('user_pw',$user_pw)->find();
        if($res == null){
            return  $this->error('原密码错误，请重新输入');
        }else
        {
            $date = [
                'user_pw' =>md5(input('pw1')),
             ];
            //  dump($date);
            //  exit;
             $res1 = Db::name('user')->where('user_id',$user_id)->update($date);
             if($res1)
            {
                return $this->success('修改成功','me/index');
            }
            else{
                return  $this->error('失败，请重新操作');
            }
        }
       
     }
}